﻿<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
    <!--作为公共模版分离出去-->
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="admin/images/rookieCs.ico" />
    <link rel="Shortcut Icon" href="admin/images/rookieCs.ico" />
    <link rel="stylesheet" type="text/css" href="admin/static/h-ui/css/H-ui.my.css" />
    <link rel="stylesheet" type="text/css" href="admin/static/h-ui.admin.pro.iframe/css/h-ui.admin.pro.iframe.min.css" />
    <link rel="stylesheet" type="text/css" href="admin/lib/Hui-iconfont/1.0.9/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="admin/static/h-ui.admin.pro.iframe/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="admin/lib/jquery-easyui/1.7.0/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="admin/lib/jquery-easyui/1.7.0/themes/icon.css" />
    <link rel="stylesheet" type="text/css" href="admin/lib/lc_switch/20160127/css/lc_switch.css" />
    <link rel="stylesheet" type="text/css" href="admin/lib/layui/2.5.6/css/layui.css" />
    <link rel="stylesheet" type="text/css" href="admin/css/iconfont/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="admin/css/mywork.css" />
    <script type="text/javascript" src="admin/lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="admin/lib/layer/3.1.1/layer.js"></script>
    <script type="text/javascript" src="admin/lib/jquery-easyui/1.7.0/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="admin/lib/jquery-easyui/1.7.0/plugins/datagrid-detailview.js"></script>
    <script type="text/javascript" src="admin/lib/jquery-easyui/1.7.0/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="admin/lib/lc_switch/20160127/js/lc_switch.min.js"></script>
    <script type="text/javascript" src="admin/lib/layui/2.5.6/layui.js"></script>
    <script>document.write('<script type="text/javascript" src="admin/js/common.js?v='+ Date.now() +'"><\/script>');</script>
    <script>document.write('<script type="text/javascript" src="admin/js/formatter.js?v='+ Date.now() +'"><\/script>');</script>
    <!--作为公共模版分离出去-->
    <title>排期核定</title>
</head>
<body class="easyui-layout" style="width: 100%; height: 100%;font-family: 微软雅黑,serif" memuId="order-ratify">
<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i> 首页
    <span class="c-gray en" style="float: none">&gt;</span> 排期管理
    <span class="c-gray en" style="float: none">&gt;</span> 排期核定
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>
<div data-options="region:'north', title:'查询条件', hideCollapsedContent:false, collapsible:true, collapsed:true" style="height:150px">
    <!--查询条件元素-->
    <div id="searchInfo" class="searchInfo">
        <div class="searchLabel">所属媒介：<span id="s_medium_userid"></span></div>
        <div class="searchLabel">所属销售：<span id="s_order_userid"></span></div>
        <div class="searchLabel">排期编号：<span id="s_order_id"></span></div>
        <div class="searchLabel">客户：<span id="s_customer_brand"></span></div>
        <div class="searchLabel">公众号：<span id="s_medium_name"></span></div>
        <div class="searchLabel"><span id="s_number_type"></span><span id="s_number_start"></span>-<span id="s_number_end"></span></div>
        <div class="searchLabel"><span id="s_date_type"></span><span id="s_date_start"></span>-<span id="s_date_end"></span></div>
        <div class="searchLabel">投放位置：<span id="s_putaddres"></span></div>
        <div class="searchLabel">是否支付：<span id="s_ispayment"></span></div>
        <div class="searchLabel">是否回款：<span id="s_isreceipt"></span></div>
        <div class="searchLabel">是否垫付：<span id="s_isadvance"></span></div>
        <div class="searchLabel"><a id="searchBtn" onclick="query(pageParam, true)"></a></div>
    </div>
</div>
<div data-options="region:'center', border:false">
    <!--表格元素-->
    <div id="tableInfo"></div>
    <!--按钮元素-->
    <div id="buttonInfo" class="buttonInfo">
        <button class="easyui-linkbutton" onclick="editOrder()"><i class="Hui-iconfont">&#xe6df;</i>修改</button>
        <button class="easyui-linkbutton" onclick="delOrder()"><i class="Hui-iconfont">&#xe6e2;</i>删除</button>
        <button class="easyui-linkbutton" onclick="calculateProfit()"><i class="Hui-iconfont">&#xe6e2;</i>重新计算利润</button>
    </div>
</div>
<script type="text/javascript">
    //准备函数
    $(function () {
        initSearchForm();
        initGrid();
        getGridHidden("tableInfo");
        query(pageParam);
    });

    //查询条件初始化
    function initSearchForm() {
        var is_supervisor_all = "0";
        //获取系统配置信息（）
        ajaxGetFun("config/getCompanyConfigByText", {text: "is_supervisor_all"}, function (bizData) {
            if (bizData != null) {
                is_supervisor_all = bizData.config_value;
            }
        }, null, "获取系统配置信息", false);
        var role_type = sessionStorage.getItem("role_type");
        var is_sup = sessionStorage.getItem("is_sup");
        $("#s_medium_userid").combobox({
            width: 100,
            prompt: "请选择媒介",
            panelHeight: "auto",
            valueField: "id",
            textField: "name",
            editable: true,
            url: role_type !== "MJB" || (is_supervisor_all === "1" && is_sup === "true") ? "user/getUserListByRoleCode?roleCode=ALL" : "user/listSubordinateUsers?hasSelf=true",
            loadFilter: function (data) {
                var temp = data.bizData;
                if (temp.length > 1) {
                    temp.unshift({"id":-1, "name":"全部"});
                }
                return temp;
            }
        });
        $("#s_order_userid").combobox({
            width: 100,
            prompt: "请选择销售",
            panelHeight: "auto",
            valueField: "id",
            textField: "name",
            editable: true,
            url: role_type !== "XSB" || (is_supervisor_all === "1" && is_sup === "true") ? "user/getUserListByRoleCode?roleCode=ALL" : "user/listSubordinateUsers?hasSelf=true",
            loadFilter: function (data) {
                var temp = data.bizData;
                if (temp.length > 1) {
                    temp.unshift({"id":-1, "name":"全部"});
                }
                return temp;
            }
        });
        $("#s_order_id").numberbox({
            width: 80,
            prompt: "请输入排期编号"
        });
        $("#s_customer_brand").textbox({
            width: 120,
            prompt: "请输入客户品牌"
        });
        $("#s_medium_name").textbox({
            width: 120,
            prompt: "请输入公众号名称"
        });
        $("#s_number_type").combobox({
            width: 110,
            panelHeight: "auto",
            valueField: "value",
            textField: "text",
            data: [{value:1, text:"执行价(元)", selected:true}, {value:2, text:"成本价(元)"}, {value:3, text:"客户税点(%)"}, {value:4, text:"客户税额(元)"}, {value:5, text:"号主税点(%)"}, {value:6, text:"号主税额(元)"}, {value:7, text:"客户返点(元)"}, {value:8, text:"号主返点(元)"}, {value:9, text:"利润(元)"}, {value:10, text:"利润率(%)"}]
        });
        $("#s_number_start").numberbox({
            width: 100,
            prompt: "请输入起始值"
        });
        $("#s_number_end").numberbox({
            width: 100,
            prompt: "请输入结束值"
        });
        $("#s_date_type").combobox({
            width: 90,
            panelHeight: "auto",
            valueField: "value",
            textField: "text",
            data: [{value:1, text:"创建日期", selected:true}, {value:2, text:"审核日期"}, {value:3, text:"付款日期"}, {value:4, text:"回款日期"}, {value:5, text:"投放日期"}, {value:6, text:"结算日期"}]
        });
        $("#s_date_start").datebox({
            width: 100,
            prompt: "请选择起始日期",
            editable: false
        });
        $("#s_date_end").datebox({
            width: 100,
            prompt: "请选择结束日期",
            editable: false
        });
        $("#s_putaddres").combobox({
            width: 80,
            prompt: "请选择投放位置",
            panelHeight: "auto",
            valueField: "text",
            data: order_putaddres_data_all
        });
        $("#s_ispayment").combobox({
            width: 80,
            prompt: "请选择是否支付",
            panelHeight: "auto",
            data: order_ispayment_data_all
        });
        $("#s_isreceipt").combobox({
            width: 80,
            prompt: "请选择是否回款",
            panelHeight: "auto",
            data: order_isreceipt_data_all
        });
        $("#s_isadvance").combobox({
            width: 80,
            prompt: "请选择是否垫付",
            panelHeight: "auto",
            data: order_isadvance_data_all
        });
        $("#searchBtn").linkbutton({
            text: '查询',
            plain: "true",
            iconCls: 'icon-search'
        });
    }

    //表格元素初始化
    function initGrid() {
        $("#tableInfo").datagrid({
            pagination: true,
            singleSelect: false,
            fitColumns: false,
            striped: true,
            fit: true,
            frozenColumns: [[
                {field: "ck", checkbox: "true"},
                {field: "id", title: "编号", width: 60, align: "center", sortable: true},
                {field: "customer_brand", title: "客户品牌", width: 100, align: "center", sortable: true},
                {field: "medium_name", title: "公众号名称", width: 120, align: "center", sortable: true},
                {field: "medium_wechat_no", title: "微信号", width: 120, align: "center", sortable: true},
                {field: "putdate", title: "投放日期", width: 90, align: "center", sortable: true, formatter: order_putdate_formatter},
                {field: "putAddress", title: "投放位置", width: 80, align: "center", sortable: true}
            ]],
            columns: [[
                {field: "quoted_price", title: "执行价", width: 80, align: "center", sortable: true, formatter: order_quoted_price_formatter},
                {field: "cost_price", title: "成本价", width: 80, align: "center", sortable: true, formatter: order_cost_price_formatter},
                {field: "customer_point", title: "客户税点", width: 70, align: "center", sortable: true, formatter: order_customer_point_formatter},
                {field: "customer_tax", title: "客户税额", width: 80, align: "center", sortable: true},
                {field: "medium_point", title: "号主税点", width: 70, align: "center", sortable: true, formatter: order_medium_point_formatter},
                {field: "medium_tax", title: "号主税额", width: 80, align: "center", sortable: true},
                {field: "customer_rebates", title: "客户返点", width: 80, align: "center", sortable: true},
                {field: "medium_rebates", title: "号主返点", width: 80, align: "center", sortable: true},
                {field: "profit", title: "利润", width: 100, align: "center", sortable: true},
                {field: "profit_rate", title: "利润率", width: 70, align: "center", sortable: true, formatter: orderProfitRateFormatter},
                {field: "payment_rate", title: "付款进度", width: 70, align: "center", sortable: true, formatter: orderPaymentRateFormatter},
                {field: "receipt_rate", title: "回款进度", width: 70, align: "center", sortable: true, formatter: orderReceiptRateFormatter},
                {field: "isadvance", title: "是否垫付", width: 70, align: "center", sortable: true, formatter: orderIsAdvanceFormatter},
                {field: "create_username", title: "创建人", width: 80, align: "center", sortable: true},
                {field: "create_date", title: "创建时间", width: 140, align: "center", sortable: true, formatter: order_create_date_formatter},
                {field: "create_desc", title: "创建备注", width: 150, align: "left", sortable: false, formatter: order_create_desc_formatter},
                {field: "audit_username", title: "审核人", width: 80, align: "center", sortable: true},
                {field: "audit_date", title: "审核时间", width: 140, align: "center", sortable: true, formatter: order_audit_date_formatter},
                {field: "medium_username", title: "对接媒介", width: 80, align: "center", sortable: true},
                {field: "status", title: "状态", width: 100, align: "center", sortable: true, formatter: order_status_formatter}
            ]],
            rowStyler: order_row_style,
            //表格工具栏元素ID
            toolbar: ".breadcrumb, #buttonInfo",
            onSortColumn: function (sort,order) {
                pageParam.pageNo = 1;
                pageParam.sort = sort;
                pageParam.order = order;
                query(pageParam);
            },
            onSelect: function (rowIndex, rowData) {
                selectedTableRow();
            },
            onUnselect: function (rowIndex, rowData) {
                selectedTableRow();
            },
            onSelectAll: function (rowIndex, rowData) {
                selectedTableRow();
            },
            onUnselectAll: function (rowIndex, rowData) {
                selectedTableRow();
            },
            onLoadSuccess: function (data) {
                toolBarBtnDisabledById([true, true, true], "buttonInfo");
            }
        });
        //表格事件
        var selectedTableRow = function() {
            var selectRow = $("#tableInfo").datagrid("getSelections");
            if (selectRow.length == 0) {
                toolBarBtnDisabledById([true, true, true], "buttonInfo");
            } else if (selectRow.length == 1) {
                toolBarBtnDisabledById([false, false, false], "buttonInfo");
            } else {
                toolBarBtnDisabledById([true, false, false], "buttonInfo");
            }
        };
        //表格分页
        var pager = $("#tableInfo").datagrid("getPager");
        pager.pagination({
            total: 0,
            rows: 0,
            pageNumber: pageParam.pageNo,
            pageSize: pageParam.pageSize,
            pageList: Page.getPageList(),
            buttons: [
                {text: "个性化设置", iconCls: "icon-tip", handler: function() {selectColumnMenu("tableInfo");}},
                {text: "&emsp;<span id='sumQuotedPrice'></span>&emsp;<span id='sumCostPrice'></span>&emsp;<span id='sumProfit'></span>&emsp;<span id='sumProfitRate'></span>"}
            ],
            onBeforeRefresh : function() {},
            onSelectPage: function(pageNumber, pageSize) {
                pageParam.pageNo = pageNumber;
                pageParam.pageSize = pageSize;
                query(pageParam);
            },
            onChangePageSize: function(pageSize) {
                pageParam.pageSize = pageSize;
            }
        });
    }

    //获取用户个性化设置
    function getGridHidden() {
        ajaxPostFun("userMenuHidden/getUserMenuHidden", {menu_id: $("body").attr("memuId"), grid_id: "tableInfo"}, function(bizData) {
            for (var i in bizData) {
                $("#tableInfo").datagrid("hideColumn", bizData[i].grid_col);
            }
        }, null, "获取用户个性化设置");
    }

    //分页查询
    function query(pageParam, goHead) {
        pageParam.medium_userid = $("#s_medium_userid").combobox("getValue");
        pageParam.order_userid = $("#s_order_userid").combobox("getValue");
        pageParam.order_id = $("#s_order_id").numberbox("getValue");
        pageParam.customer_brand = $("#s_customer_brand").textbox("getValue").trim();
        pageParam.medium_name = $("#s_medium_name").textbox("getValue").trim();
        pageParam.number_type = $("#s_number_type").combobox("getValue");
        pageParam.number_start = $("#s_number_start").numberbox("getValue");
        pageParam.number_end = $("#s_number_end").numberbox("getValue");
        pageParam.date_type = $("#s_date_type").combobox("getValue");
        pageParam.date_start = $("#s_date_start").datebox("getValue");
        pageParam.date_end = $("#s_date_end").datebox("getValue");
        pageParam.putAddress = $("#s_putaddres").combobox("getValue");
        pageParam.ispayment = $("#s_ispayment").combobox("getValue");
        pageParam.isreceipt = $("#s_isreceipt").combobox("getValue");
        pageParam.isadvance = $("#s_isadvance").combobox("getValue");
        if (goHead && goHead)
            pageParam.pageNo = 1;
        var successFun = function(bizData) {
            $("#tableInfo").datagrid("loadData", bizData.rows);
            $("#tableInfo").datagrid("getPager").pagination({pageNumber: bizData.page, total: bizData.records});
            //展示统计栏
            $("#sumQuotedPrice").html("总执行价："+ bizData.statData.sumQuotedPrice +"元");
            $("#sumCostPrice").html("总成本价："+ bizData.statData.sumCostPrice +"元");
            $("#sumProfit").html("总利润："+ bizData.statData.sumProfit +"元");
            $("#sumProfitRate").html("总利润率："+ bizData.statData.sumProfitRate +"%");
        };
        var errorFun = function() {
            showFailedMsg("查询数据出错");
        };
        ajaxGetFun("order/queryRatifyOrderPage", pageParam, successFun, errorFun, "排期列表");
    }

    //修改
    function editOrder() {
        var selectRows = $("#tableInfo").datagrid("getSelections");
        if (selectRows.length != 1) {
            return showWarnMsg("请选择一条条目后操作");
        }
        var openedFun = function (index, layero) {
            var row = copyObj(selectRows[0]);
            row.putdate = dates("Y-m-d", row.putdate);
            $("iframe")[0].contentWindow.$("#formInfo").form("load", row);
            $("iframe")[0].contentWindow.$("#customer_id").combobox("reload", "customer/listBrandsByUserId?userId="+ selectRows[0].createUserId);
        };
        var saveFun = function(index, layero) {
            var formEle = layero.find("iframe")[0].contentWindow.$("#formInfo");
            if (formEle.form("validate")) {
                var yw_orderInfo = getFormJson(formEle);
                var successFun = function(bizData) {
                    layer.close(index);
                    query(pageParam, true);
                    showSuccessMsg("修改成功");
                };
                ajaxPostFun("order/ratifyUpdateInfo", yw_orderInfo, successFun, null, "修改排期");
            }
        };
        openIframe(false, 500, 500, "order-info.html", openedFun, saveFun);
    }

    //删除
    function delOrder() {
        var selectRows = $("#tableInfo").datagrid("getSelections");
        if (selectRows.length === 0) {
            return showWarnMsg("请选择条目后操作");
        }
        var ids = mergedRowCell(selectRows, "id");
        layer.confirm('确认要删除选中的排期吗？', function(index) {
            var successFun = function(bizData) {
                showSuccessMsg("已删除"+ bizData +"条数据");
                query(pageParam, true);
            };
            ajaxPostFun("order/ratifyDeleteInfoByIds", {ids: ids}, successFun, null, "删除排期");
        });
    }

    //重新计算利润
    function calculateProfit() {
        var selectRows = $("#tableInfo").datagrid("getSelections");
        if (selectRows.length === 0) {
            return showWarnMsg("请选择条目后操作");
        }
        var ids = mergedRowCell(selectRows, "id");
        layer.confirm("您确定要重新计算当前选中排期的利润吗？", function(index) {
            var successFun = function(bizData) {
                showSuccessMsg("操作成功"+ bizData +"条数据");
                query(pageParam, true);
            };
            ajaxPostFun("order/calculateProfitByIds", {ids: ids}, successFun, null, "删除排期");
        });
    }
</script> 
</body>
</html>